package com.ruoyi.service;

import com.ruoyi.entity.SxfReserveOrder;
import com.ruoyi.mapper.SxfReserveOrderMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bean.SxfReserveOrderFrom;
import com.sxftech.resp.ResponseData;
/**
 * <p>
 * 预约子订单 服务实现类
 * </p>
 *
 * @author liuxing
 * @since 2020-10-30
 */
@Service
public class SxfReserveOrderService extends ServiceImpl<SxfReserveOrderMapper, SxfReserveOrder> {

	public ResponseData create(SxfReserveOrderFrom sxfReserveOrder) {
		SxfReserveOrder entity = transformationFrom(sxfReserveOrder);
		this.save(entity);
		return ResponseData.success("新增成功");
	}
	
	public ResponseData modify(SxfReserveOrderFrom sxfReserveOrder) {
		if(findById(sxfReserveOrder.getId())== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfReserveOrder entity = transformationFrom(sxfReserveOrder);
		entity.setId(sxfReserveOrder.getId());
		this.updateById(entity);
		return ResponseData.success("修改成功");
	}

	public SxfReserveOrder transformationFrom(SxfReserveOrderFrom sxfReserveOrder) {
		SxfReserveOrder entity = new SxfReserveOrder();
		entity.setOrderId(sxfReserveOrder.getOrderId());
		entity.setParkingLot(sxfReserveOrder.getParkingLot());
		entity.setParkingLotCode(sxfReserveOrder.getParkingLotCode());
		entity.setPlAddress(sxfReserveOrder.getPlAddress());
		entity.setParkingSpace(sxfReserveOrder.getParkingSpace());
		entity.setParkingSpaceId(sxfReserveOrder.getParkingSpaceId());
		entity.setPlateNumber(sxfReserveOrder.getPlateNumber());
		entity.setReserveMinutes(sxfReserveOrder.getReserveMinutes());
		entity.setParkingTime(sxfReserveOrder.getParkingTime());
		entity.setEnterTime(sxfReserveOrder.getEnterTime());
		entity.setLeaveTime(sxfReserveOrder.getLeaveTime());
		entity.setPriceSystemCode(sxfReserveOrder.getPriceSystemCode());
		entity.setSpaceProperty(sxfReserveOrder.getSpaceProperty());
		entity.setExpiryDate(sxfReserveOrder.getExpiryDate());
		entity.setSpaceOwnerMobile(sxfReserveOrder.getSpaceOwnerMobile());
		entity.setOvertimeRemark(sxfReserveOrder.getOvertimeRemark());
		entity.setChargeGate(sxfReserveOrder.getChargeGate());
		entity.setLocalId(sxfReserveOrder.getLocalId());
		entity.setDiscount(sxfReserveOrder.getDiscount());
		entity.setSpaceType(sxfReserveOrder.getSpaceType());
		entity.setCreateTime(sxfReserveOrder.getCreateTime());
		entity.setModifyTime(sxfReserveOrder.getModifyTime());
		entity.setRoId(sxfReserveOrder.getRoId());
		return entity;
	}

	public SxfReserveOrderFrom transformationBean(SxfReserveOrder sxfReserveOrder) {
		SxfReserveOrderFrom from = new SxfReserveOrderFrom();
		from.setOrderId(sxfReserveOrder.getOrderId());
		from.setParkingLot(sxfReserveOrder.getParkingLot());
		from.setParkingLotCode(sxfReserveOrder.getParkingLotCode());
		from.setPlAddress(sxfReserveOrder.getPlAddress());
		from.setParkingSpace(sxfReserveOrder.getParkingSpace());
		from.setParkingSpaceId(sxfReserveOrder.getParkingSpaceId());
		from.setPlateNumber(sxfReserveOrder.getPlateNumber());
		from.setReserveMinutes(sxfReserveOrder.getReserveMinutes());
		from.setParkingTime(sxfReserveOrder.getParkingTime());
		from.setEnterTime(sxfReserveOrder.getEnterTime());
		from.setLeaveTime(sxfReserveOrder.getLeaveTime());
		from.setPriceSystemCode(sxfReserveOrder.getPriceSystemCode());
		from.setSpaceProperty(sxfReserveOrder.getSpaceProperty());
		from.setExpiryDate(sxfReserveOrder.getExpiryDate());
		from.setSpaceOwnerMobile(sxfReserveOrder.getSpaceOwnerMobile());
		from.setOvertimeRemark(sxfReserveOrder.getOvertimeRemark());
		from.setChargeGate(sxfReserveOrder.getChargeGate());
		from.setLocalId(sxfReserveOrder.getLocalId());
		from.setDiscount(sxfReserveOrder.getDiscount());
		from.setSpaceType(sxfReserveOrder.getSpaceType());
		from.setCreateTime(sxfReserveOrder.getCreateTime());
		from.setModifyTime(sxfReserveOrder.getModifyTime());
		from.setRoId(sxfReserveOrder.getRoId());

		return from;
	}

	
	public SxfReserveOrderFrom findById(String id) {
		SxfReserveOrder entity = this.getOne(new QueryWrapper<SxfReserveOrder>().lambda()
				.eq(SxfReserveOrder::getId, id)
				);
		if(entity == null) return null;
		return transformationBean(entity);
	}
	
	public ResponseData remove(String id) {
		if(findById(id)== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfReserveOrder sxfReserveOrder = new SxfReserveOrder();
		sxfReserveOrder.setId(id);
		this.updateById(sxfReserveOrder);
		return ResponseData.success("删除成功");
	}
	
	public IPage pageList(Integer page, Integer size, SxfReserveOrderFrom ibean) {
		return this.page(new Page(page, size), new QueryWrapper<SxfReserveOrder>().lambda()
				.eq(ibean.getOrderId() != null, SxfReserveOrder::getOrderId, ibean.getOrderId())
				.eq(StringUtils.isNotEmpty(ibean.getParkingLot()), SxfReserveOrder::getParkingLot, ibean.getParkingLot())
				.eq(StringUtils.isNotEmpty(ibean.getParkingLotCode()), SxfReserveOrder::getParkingLotCode, ibean.getParkingLotCode())
				.eq(StringUtils.isNotEmpty(ibean.getPlAddress()), SxfReserveOrder::getPlAddress, ibean.getPlAddress())
				.eq(StringUtils.isNotEmpty(ibean.getParkingSpace()), SxfReserveOrder::getParkingSpace, ibean.getParkingSpace())
				.eq(ibean.getParkingSpaceId() != null, SxfReserveOrder::getParkingSpaceId, ibean.getParkingSpaceId())
				.eq(StringUtils.isNotEmpty(ibean.getPlateNumber()), SxfReserveOrder::getPlateNumber, ibean.getPlateNumber())
				.eq(ibean.getReserveMinutes() != null, SxfReserveOrder::getReserveMinutes, ibean.getReserveMinutes())
				.eq(ibean.getParkingTime() != null, SxfReserveOrder::getParkingTime, ibean.getParkingTime())
				.eq(ibean.getEnterTime() != null, SxfReserveOrder::getEnterTime, ibean.getEnterTime())
				.eq(ibean.getLeaveTime() != null, SxfReserveOrder::getLeaveTime, ibean.getLeaveTime())
				.eq(StringUtils.isNotEmpty(ibean.getPriceSystemCode()), SxfReserveOrder::getPriceSystemCode, ibean.getPriceSystemCode())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceProperty()), SxfReserveOrder::getSpaceProperty, ibean.getSpaceProperty())
				.eq(ibean.getExpiryDate() != null, SxfReserveOrder::getExpiryDate, ibean.getExpiryDate())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceOwnerMobile()), SxfReserveOrder::getSpaceOwnerMobile, ibean.getSpaceOwnerMobile())
				.eq(StringUtils.isNotEmpty(ibean.getOvertimeRemark()), SxfReserveOrder::getOvertimeRemark, ibean.getOvertimeRemark())
				.eq(ibean.getChargeGate() != null, SxfReserveOrder::getChargeGate, ibean.getChargeGate())
				.eq(StringUtils.isNotEmpty(ibean.getLocalId()), SxfReserveOrder::getLocalId, ibean.getLocalId())
				.eq(ibean.getDiscount() != null, SxfReserveOrder::getDiscount, ibean.getDiscount())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceType()), SxfReserveOrder::getSpaceType, ibean.getSpaceType())
				.eq(ibean.getCreateTime() != null, SxfReserveOrder::getCreateTime, ibean.getCreateTime())
				.eq(ibean.getModifyTime() != null, SxfReserveOrder::getModifyTime, ibean.getModifyTime())
				.eq(ibean.getRoId() != null, SxfReserveOrder::getRoId, ibean.getRoId())
				);
	}
}
